home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-06 | 3.8 KB | 136 lines | [TEXT/MACA] |
- \ 12.5.89 rfl general resource handling classes
- \ 2.1.90 rfl resrc now subclass of handle
- \ 11.28.90 rfl added type: stringlist
- \ 10.20.91 rfl took out abort if sound resource snd not found
-
- create copyHandle popa0 " HandToHand" asmcall pusha0 next,
-
- :CLASS resrc <super handle
-
- int resID
-
- :M putResID: put: resID ;M
- :M error: word0 call ResError i->l ;M
- :M changed: m@ call changedResource error: self abort" no Change" ;M
- :M save: changed: self m@ call writeResource error: self abort" no Write" ;M
- :M getRef: ( -- n) word0 m@ call HomeResFile i->l ;M
- :M close: getref: self makeint call closeResFile ;M
- :M release: m@ call releaseResource 0 m! ;M
- :M size: 0 m@ call sizeResource ;M
- :M detach: m@ call detachResource ;M
- :M remove: m@ call rmveResource ;M
- :M add: { type resID addr len -- }
- m@ type resID makeint addr len str255 call addResource ;M
- :M getnew: ( restype -- ) get: resID swap (getres) dup m! not IF errbeep THEN ;M
-
- ;CLASS
-
- false value quiet \ global true if want sounds
-
- \ resource type 'snd'
- :CLASS snd <super resrc
-
- int async
- var sndChannel
-
- :M async: 1 put: async ;M
- :M sync: clear: async ;M
-
- :M getNew: 'type snd getNew: super ;M
-
- :M newChannel: 0 abs: sndChannel word0 0 0 call SndNewChannel drop ;M
- :M disposeChannel: 0 abs: sndChannel word0 call SndDisposeChan drop ;M
-
- \ the sound is already loaded in. this will just play the sound
- :M play: ( --) 0 get: async
- IF newChannel: self get: sndChannel m@ 1 bool call SndPlay disposeChannel: self
- ELSE 0 m@ word0 call SndPlay
- THEN drop ;M
-
- \ like picture disp: ; resID on stack, this will say the sound and leave it in heap
- :M disp: ( resID --) put: resID getnew: self play: self ;M
-
- \ the resID is stored with the object, say: will load the sound and say it
- :M say: ( --) getNew: self play: self ;M
-
- \ to be used to take an resID from stack, load a sound, say it, and purge it
- \ like getstring; no action if quiet=true
- :M blurt: ( resID --) quiet not IF disp: self release: self ELSE drop THEN ;M
-
- ;CLASS
-
- snd sound \ instantiate a global sound object
-
- : ?say ( b snd# --) swap IF blurt: sound ELSE drop THEN ;
-
- \ 8.25.89 rfl class for handling STR# resources. This is basically a static
- \ string array. Put STR# into resource file, and handle it this
- \ way, however the maximum string length is 255 characters.
- \ Eventually, the array could be made dynamic.
-
- :CODE @String ( ind addr -- addr len t or f )
- clr.l d1
- movea.l (sp)+,a0 \ get resource addr
- move.l (sp)+,d0 \ get index
- adda.l a3,a0
- move.w (a0)+,d7 \ get # of strings
- subq #1,d7
- cmp.w d0,d7 \ within limits?
- bge loop
- error clr.l -(sp)
- bra exit
- loop move.b (a0)+,d1 \ get len
- subq.l #1,d0 \ dec index
- cmpi.l #-1,d0
- beq out
- adda.l d1,a0 \ go to next index
- bra loop
- out suba.l a3,a0
- move.l a0,-(sp)
- move.l d1,-(sp)
- move.l #1,-(sp)
- exit nop
- ;code
-
- hex \ compare two strings case insensitive
- create s=' ( addr len addr len -- tf)
- 201f w, \ move.l (sp)+,d0
- 225f w, \ movea.l (sp)+,a1
- 241f w, \ move.l (sp)+,d2
- 2057 w, \ movea.l (sp),a0
- 4840 w, \ swap d0
- 3002 w, \ move.w d2,d0
- 4840 w, \ swap d0
- d1cb w, \ adda.l a3,a0
- d3cb w, \ adda.l a3,a1
- a03c w, \ call equalString
- 0a00 w, 1 w, \ eori.b #1,d0
- 2e80 w, \ move.l d0,(sp)
- next,
- decimal
-
- \ resource type 'STR#'
- :CLASS StringList <super resrc
-
- :M getNew: 'type STR# getnew: super ;M
-
- \ returns # of elements
- :M limit: ( -- n) ptr: self w@ ;M
-
- :M size: limit: self ;M
-
- :M at: ( ind -- addr len) ptr: self @string 0= classerr" 129 ;M
-
- :M type: ( ind --) i at: self type ;M
-
- :M print: limit: self 0 DO i 3 .r space i at: self type cr ?pause LOOP ;M
-
- \ finds with case insensitive
- :M indexOf: { addr len \ flag -- ind t or f }
- limit: self 0 false -> flag
- DO addr len i at: self s=' IF i true -> flag LEAVE THEN LOOP
- flag ;M
-
- ;CLASS
-
-